home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 880 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: news.infi.net!usenet
  2. From: nngis@norfolk.infi.net (Greg DiGiorgio)
  3. Newsgroups: comp.lang.c,alt.msdos.programmer
  4. Subject: Re: Two strange C problems.
  5. Date: 9 Jan 1996 13:22:49 GMT
  6. Organization: Customer of InfiNet
  7. Distribution: world
  8. Message-ID: <4ctq79$27l@news.infi.net>
  9. References: <4cojb2$qog@lugb.latrobe.edu.au>
  10. Reply-To: nngis@norfolk.infi.net
  11. NNTP-Posting-Host: h-overdrive.norfolk.infi.net
  12. Mime-Version: 1.0
  13. X-Newsreader: WinVN 0.99.3
  14.  
  15. In article <4cojb2$qog@lugb.latrobe.edu.au>, cs102238@lux.latrobe.edu.au 
  16. says...
  17. >
  18. >I have two C problems.
  19. >
  20.  
  21. For time's sake, I am not replying to the first problem...
  22.  
  23. >
  24. >PROBLEM 2 :
  25. >
  26. >const escape=27;
  27. >const cr=13;
  28. >const bs=8;
  29. >
  30. >while (ch!=cr)
  31. >{
  32. >     .
  33. >     .
  34. >     .
  35. >}
  36. >
  37. >while (ch!=escape)
  38. >{
  39. >     .
  40. >     .
  41. >     .
  42. >}
  43. >
  44. >If I replace the 27 with \27' or the 13 with '\13' then these loops 
  45. don't
  46. >work i.e. an infinite loop results. WHY?
  47.  
  48. Because the following line:
  49.  
  50.      int ch = '\27';
  51.  
  52. is in Octal. That is, '\27' specifies an octal value, not decimal. So the 
  53. '27' is in base 8 and ends up being actually 23 in base 10 - not what you 
  54. expect. 'C' has built-in "escape sequences" for most of what you want:
  55.  
  56.      int ch = '\n';    /* new line */
  57.  
  58. For the escape char, convert to hexadecimal and use:
  59.  
  60.      int ch = '\x17';  /* This is 27 decimal */
  61.  
  62.  
  63. >
  64. >Also if I want to do somthing like this : puts("\24 \25"); which should
  65. >print the up and down arrows on the screen (ASCII 24 and 25), but no, it
  66. >prints some other ASCII characters. As far as I can tell C has its own
  67. >unique character table, at least for the control characters. WHY?
  68.  
  69. Same reason here...
  70.  
  71. >
  72. >Sometimes I wonder whether some one needs to go back an rewrite the damn
  73. >language so that it works sensibly and predictably like Pascal can be
  74. >relied upon to do.
  75.  
  76. When I first started in 'C' programming in 1988, I too took solace in my 
  77. knowledge of Pascal - which was the dominant teaching language when I was 
  78. in college. In fact, when I came to a shop where 'C' was king, I 
  79. continued programming my projects in Pascal. But as I learned 'C' and 
  80. felt comfortable with the language, I shucked Pascal in a hurry. You just 
  81. can not do many things in Pascal as simply as you can in 'C'. 
  82.  
  83. True, Pascal has some great abstract data types like "sets", but for my 
  84. money, I'll take 'C'. Plus, most commercial developers use 'C', not 
  85. Pascal. Plus, UNIX OS's come with (sometime its optional) a 'C' compiler, 
  86. not Pascal. Plus, UNIX was written in 'C', Plus, Windows is written in 
  87. 'C'. Plus, the only Pascal that is even remotely popular is Delphi and 
  88. it only works in Windows. But if you choose 'C', you have a choice of 
  89. vendors and platforms.
  90.  
  91. Hope this helps some,
  92. Greg DiGiorgio
  93.  
  94.